package cliente;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class InterfazCliente extends JFrame implements ActionListener{
	private JTextField textField;
	private JTextArea textArea;
	private JButton boton;
	
	public InterfazCliente() {
		super("Chat");

		//Create a regular text field
	    textField = new JTextField(10);
		textField.setActionCommand("");
		textField.addActionListener((ActionListener) this);
		
		boton = new JButton();
		boton.setText("Enviar");
		
		
		//Layout the text controls and the labels
		JPanel textControlsPane = new JPanel();
		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		c = new GridBagConstraints();
		c.anchor = GridBagConstraints.EAST;
		c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
		c.fill = GridBagConstraints.NONE;      //reset to default
		c.weightx = 0.0;                       //reset to default
		c.gridwidth = GridBagConstraints.REMAINDER;     //end row
		c.fill = GridBagConstraints.HORIZONTAL;
		c.weightx = 1.0;
		gridbag.setConstraints(textField, c);
		textControlsPane.add(textField);
		textControlsPane.setLayout(gridbag);
	    c.gridwidth = GridBagConstraints.REMAINDER; //last
		c.anchor = GridBagConstraints.WEST;
		c.weightx = 1.0;
		textControlsPane.setBorder(
			BorderFactory.createCompoundBorder(
					BorderFactory.createTitledBorder("Nick"),
					BorderFactory.createEmptyBorder(5,5,5,5)));

		//Create a text area
	    textArea = new JTextArea(5, 10);
		textArea.setLineWrap(true);
		textArea.setWrapStyleWord(true);
	    JScrollPane areaScrollPane = new JScrollPane(textArea);
		areaScrollPane.setVerticalScrollBarPolicy(
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		areaScrollPane.setPreferredSize(new Dimension(250, 250));
		areaScrollPane.setBorder(
		    BorderFactory.createCompoundBorder(
			BorderFactory.createCompoundBorder(
					BorderFactory.createTitledBorder("Mensajes"),
					BorderFactory.createEmptyBorder(5,5,5,5)),
			areaScrollPane.getBorder()));

		//Create an editor pane
	    JEditorPane editorPane = new JEditorPane();
	    JScrollPane editorScrollPane = new JScrollPane(editorPane);
		editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		editorScrollPane.setPreferredSize(new Dimension(250, 150));

		//Create a text pane
	    JTextPane textPane = new JTextPane();
	    JScrollPane paneScrollPane = new JScrollPane(textPane);
		paneScrollPane.setPreferredSize(new Dimension(250, 150));


		//Put everything in the applet
		JPanel leftPane = new JPanel();
		BoxLayout leftBox = new BoxLayout(leftPane, BoxLayout.Y_AXIS);
		leftPane.setLayout(leftBox);
		leftPane.add(textControlsPane);
		leftPane.add(areaScrollPane);
		leftPane.add(boton);

		JPanel contentPane = new JPanel();
		BoxLayout box = new BoxLayout(contentPane, BoxLayout.X_AXIS);
		contentPane.setLayout(box);
		contentPane.add(leftPane);
		setContentPane(contentPane);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
	public String LeerNick(){
		return textField.getText();
	}
	
	public void EscribirMensajes(String texto){
		textArea.setText(texto);
	}
}
